import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface DashboardStats {
  totalComments: number;
  positiveRatio: number;
  negativeRatio: number;
  processedRatio: number;
  dailyTrend: { date: string; count: number }[];
  tagDistribution: { tag: string; count: number; color: string }[];
  modelUsage: { model: string; usage: number }[];
}

interface DashboardState {
  stats: DashboardStats;
  loading: boolean;
  error: string | null;
}

const initialState: DashboardState = {
  stats: {
    totalComments: 0,
    positiveRatio: 0,
    negativeRatio: 0,
    processedRatio: 0,
    dailyTrend: [],
    tagDistribution: [],
    modelUsage: []
  },
  loading: false,
  error: null
};

const dashboardSlice = createSlice({
  name: 'dashboard',
  initialState,
  reducers: {
    fetchDashboardStatsStart: (state) => {
      state.loading = true;
      state.error = null;
    },
    fetchDashboardStatsSuccess: (state, action: PayloadAction<DashboardStats>) => {
      state.loading = false;
      state.stats = action.payload;
    },
    fetchDashboardStatsFailure: (state, action: PayloadAction<string>) => {
      state.loading = false;
      state.error = action.payload;
    }
  }
});

export const {
  fetchDashboardStatsStart,
  fetchDashboardStatsSuccess,
  fetchDashboardStatsFailure
} = dashboardSlice.actions;

export default dashboardSlice.reducer;
    